-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String operators and builtin functions #38
Conversation
Having thought a bit more, the question seems to boil down to one of type separarion. One strategy would be to support implicit type conversion (e.g. |
Hey bittrance, thank you for your interest in this crate and for your contribution. I have a few remarks:
That's it so far. I will also take a look at the code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the code and I think it looks good. There are some minor things here and there.
And I see you did not implement the auto-conversion yet. I would accept the pull-request without, that's fine. But then we should definetly make an issue for the auto-conversion
(I just started a new job and moved to a new location, so my work on this is slowed down a bit. But as soon as I get internet at home, I will be able to care for this crate properly again.) |
I understand your plan to have namespaces and it would make sense for some use cases, particularly where the developer doesn't have control over the runtime list of available functions, but I'm not sure it will make much sense to my users. If I use
Prefixing the functions with I could add functions into namespaces as per your description and introduce re-exporting functions so that my project can make the string functions available in the root namespace as well. Does that make sense? Regarding type conversions, I have come to realize that this should rather be discussed in terms of type safety (not just separation). In particular, I think that I would like to be able to validate that the resulting type of an expression is correct when I load it. This is a separate issue from string functions, so I will do some research and open a separate issue to explain my thinking. Regarding regex method naming, note https://docs.rs/regex/1.1.5/regex/struct.Regex.html#using-the-stdstrpattern-methods-with-regex . Some digging points to rust-lang/rust#27721 ( The rest of the comments are straight-forward changes that I will incorporate when I update the code pending resolution of these discussions. |
Hey bittrance, I understand your concern about namespaces being too verbose for your use case. I think we can easily resolve that by adding something like an For the sake of moving this forward, we could just merge the pull request without the namespacing changes, so you name all your methods without About type conversions, I think we can also merge this pull request without the auto-conversion feature into strings. Can all be added separately. I think we should not overload this pull request. For the regex naming, I think there should be a differentiation between calling for example the matches method with a regex, or with a simple string pattern. Since string patterns might also contain control-characters of regexes, which might then be confusing to the user. I think I would rather have separate methods for regex/non-regex operations. So for now I guess |
…), trim, upcase. New dependency regex.
…e(regex), trim, upcase. New dependency regex.
Also simplify their error handling.
bf2bd51
to
dbf3949
Compare
I went with your original suggestion to namespace with I hid the parts dependent on regex behind a feature flagn (excluding the error variant and its support which are not dependent on anything from the actual crate). Not sure feature flagging individual match arms is best practice, but I think that problem should be solved in the more general context of namespaces and modularized builtins. I force-pushed the branch in order to make the regex dependency optional in all commits so as to not break future bisection. |
Okay that sounds good. For feature flagging individual match arms: I'm fine with that. Right now there are so little builtins that this list is easy to comprehend. |
Thank you for your contribution! You seem to write really good code. |
I'm planning a project which will have both rules (i.e. boolean expressions) and transformations (i.e. string expressions) in the same configuration entry, so it makes sense to use a library with support for both to get a unified syntax for these expressions. Evalexpr almost fills this description, but would need a bit more string support. Given that these functions are pretty standard, I thought it makes sense to contribute them upstream rather than keep them locally.
This PR introduces common operations for strings:
This PR adds a dependence on the
regex
crate. This should probably be optional, but I'm thinking it is so likely that a string user will want to use regexes that it might make more sense to try to make all string functions optional?